package com.club.controller;

import com.club.service.ChartsService;
import com.club.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("charts")
@CrossOrigin
public class ChartsController {
    @Autowired
    ChartsService chartsService;
    @RequestMapping("chartsA")
    public Result chartsA(){
        List<HashMap> list=chartsService.chartA();
        System.out.println(list);
        List nameList=new ArrayList<>();
        List countList=new ArrayList<>();
        for(HashMap item:list){
            nameList.add( item.get("name"));
            countList.add( item.get("courseCount"));
        }
        Map map=new HashMap();
        map.put("name",nameList);
        map.put("courseCount",countList);
        return Result.success(map);
    }
}
